package com.group3.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiResponse<T> {
    private Integer code;
    private String message;
    private T data;



    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(200, "操作成功", data);
    }

    public static <T> ApiResponse<T> success() {
        return new ApiResponse<>(200, "操作成功", null);
    }

    public static <T> ApiResponse<T> success(String message, T data) {
        return new ApiResponse<>(200, message, data);
    }

    public static <T> ApiResponse<PageData<T>> successPage(T data, long total, int current, int size) {
        return new ApiResponse<>(200, "操作成功", new PageData<>(data, total, current, size));
    }

    public static ApiResponse<?> error(String message) {
        return new ApiResponse<>(500, message, null);
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    static class PageData<T> {
        private T records;
        private long total;
        private int current;
        private int size;
    }
}